package Player
{
	import adobe.utils.CustomActions;
	import BasicEngine.Dispatcher;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.utils.Dictionary;
	public class AnimationEntData extends VisualEntData
	{
		public  var VelocityX:int;
		public  var VelocityY:int;
		
		private var currentAnimation:String = "";
		private var animationList:Dictionary;	
		private var updateFunc:Dictionary;
		
		
		
		/**
		 * 0:北 1:南 2:西 3:东
		 */
		public var faceDirect:int;
		
		public var keycode:int = -1;
		
		/**
		 * 路径 
		 */
		public var DesPoints:Vector.<Point>
		
		public var target:Point = new Point();
		
		public var move:Boolean = false;
		
		public function get CurrentAnimation():AnimationUnit
		{			
			return GetAnimation(currentAnimation);
		}		
		
		public function AnimationEntData(_id:int)
		{
			super(_id);
			animationList = new Dictionary();
			updateFunc = new Dictionary();
			var data:AnimationEntData = this;			
			this.ImgContainer.addEventListener(Event.ENTER_FRAME, function(e:Event):void {
			for each(var item:Function in updateFunc)
				{
					item(data);
				}
			});
			VelocityY = 0;
		    VelocityX = 0;
		}   
		
		public override function Init(_intOfBmpDatas:Array, _default:int = 0):void 
		{
			super.Init(_intOfBmpDatas, _default);
		}
		
		public function AddAnimationUnit(_unit:AnimationUnit):void
		{
			animationList[_unit.Name] = _unit;
		}
		
		public function AddUpdateProc(_proc:Function,_key:String):void
		{
			updateFunc[_key] = _proc;
		}
		
		public function RemoveUpdateProc(_key:String):void
		{
			delete updateFunc[_key];
		}
		
		/**
		 * 切换动画
		 * 将上一个动画的计时器归零,将当前动画计时器增加到临界状态,以避免等待
		 */
		public function SwitchAnimation(_animationName:String):void
		{		
			if (_animationName != currentAnimation)
			{	
			   var oldAnimation:AnimationUnit = GetAnimation(currentAnimation);
			   if(oldAnimation != null)
			       oldAnimation.delayConter = 0;
			   currentAnimation = _animationName;	
			   
			   var anim:AnimationUnit = GetAnimation(currentAnimation);
			   anim.delayConter = anim.Delay;
			}
		}
		
		private function GetAnimation(_unitName:String):AnimationUnit
		{
			return animationList[_unitName];
		}	
		
		
	}
}